/*
 * @lc app=leetcode.cn id=35 lang=java
 *
 * [35] 搜索插入位置
 */

// @lc code=start
class Solution {
    public int searchInsert(int[] nums, int target) {
        int start=0;
        int end=nums.length-1;
        int middle=end;
        int ans=end+1;
        while (start<=end) {
            middle=start+end;
            middle/=2;
            if (nums[middle]==target) {
                return middle;
            }
            if (nums[middle]>target) {
                end=middle-1;
                ans=middle;
            }else{
                start=middle+1;
                
            }
        }
       return ans;
    }

}

